var api = require('../../util/api.js');
Page({
    data: {
        examineId: "",
        name: '',
        startTime: '',
        finishTime: '',
        array: [],
        canSubmit: false
    },
    onLoad: function () {
        var _this = this;
        let chain = api.chain();
        api.get(`${api.url.examine}/${chain.examineId}`).then(res => {
            _this.setData({
                examineId: chain.examineId,
                name: res.data.name,
                startTime: res.data.startTime,
                finishTime: res.data.finishTime,
                canSubmit: res.data.status != '0',
                subType: res.data.subType
            });
        });
        api.getDic('lhjd_type').then(res => {
            let subType = _this.data.subType;
            _this.setData({
                array: res,
                index: api.getDicIndex(subType, res)
            });
        });
    },
    submit() {
        this.checkSubmit();
        api.put(api.url.examine, {
            id: this.data.examineId,
            startTime: this.data.startTime,
            finishTime: this.data.finishTime,
            name: this.data.name,
            subType: this.data.subType
        }).then(res => {
            api.back('修改成功','success');
        })
    },
    khname(e) {
        this.setData({
            name: e.detail.value
        })
    },
    DateChange1: function (t) {
        this.setData({
            startTime: t.detail.value
        });
    },
    DateChange2: function (t) {
        this.setData({
            finishTime: t.detail.value
        });
    },
    checkSubmit: function () {
        if (this.data.name == '') {
            wx.showToast({
                title: '考核名称不能为空',
                icon: 'none'
            })
            return
        }
    },
    bindPickerChange: function (e) {
        let _this = this;
        let index = e.detail.value;
        _this.setData({
            index: index,
            subType: _this.data.array[index].dictValue
        });
    }
});